//
//  HBVc.swift
//  GjCup
//
//  Created by abc on 2024/4/9.
//

import UIKit

class HBVc: UIViewController {
    
    
    @IBOutlet weak var dView: HYLDrawView!{
        didSet{
            dView.layer.cornerRadius = 12
            dView.layer.masksToBounds = true
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        dView.lineWidth = 5

    }
    
    
    @IBAction func cheAc(_ sender: UIButton) {
        dView.cancel()
    }
    
    @IBAction func caAc(_ sender: UIButton) {
        dView.lineWidth = 40
        dView.pathColor = UIColor.white
    }
    @IBAction func qingAc(_ sender: UIButton) {
        dView.clear()
    }
    
    @IBAction func saveImg(_ sender: UIBarButtonItem) {
        UIGraphicsBeginImageContext(dView.bounds.size)
        guard let context = UIGraphicsGetCurrentContext() else { return  }
        
        dView.layer.render(in: context)
        guard let image = UIGraphicsGetImageFromCurrentImageContext() else { return  }
        UIGraphicsEndImageContext()
        UIImageWriteToSavedPhotosAlbum(image, nibName, nil, nil)
        UIAlertController.ok_alert("图片已保存，请前往相册查看", self)
    }
    
    
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
        if segue.identifier == "HBTc" {
            let vc = segue.destination as! HBCcVc
            vc.block = { [weak self] color in
                self?.dView.pathColor = UIColor(hex: color)
                self?.dView.lineWidth = 5
            }
            
        }
    }
    

}
